package com.yx.outSourcing.controller;


import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.yx.outSourcing.R.Result;
import com.yx.outSourcing.entity.dto.OutsourcingPersonDTO;
import com.yx.outSourcing.entity.vo.AccessApplicationVO;
import com.yx.outSourcing.entity.vo.OutsourcingPersonVO;
import com.yx.outSourcing.service.IAccessApplicationService;
import com.yx.outSourcing.service.IOutsourcingPersonService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;

import lombok.RequiredArgsConstructor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * <p>
 * 外协人员信息表 前端控制器
 * </p>
 *
 * @author zcc
 * @since 2025-07-29
 */
@Api(tags = "外协人员管理接口")
@RestController
@RequestMapping("/api/out")
@RequiredArgsConstructor
public class OutsourcingPersonController {

    @Autowired
    private IOutsourcingPersonService outsourcingPersonService;

    /**
     * 查询外协人员列表
     * @param name
     * @param idCard
     * @param companyName
     * @param startDate
     * @param endDate
     * @param status
     * @param pageNum
     * @param pageSize
     * @return
     */
    @GetMapping("/list")
    @ApiOperation("查询外协人员列表")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "name", value = "姓名", paramType = "query"),
            @ApiImplicitParam(name = "idCard", value = "身份证号", paramType = "query"),
            @ApiImplicitParam(name = "companyName", value = "公司名称", paramType = "query"),
            @ApiImplicitParam(name = "startDate", value = "入厂日期起(yyyy-MM-dd)", paramType = "query"),
            @ApiImplicitParam(name = "endDate", value = "入厂日期止(yyyy-MM-dd)", paramType = "query"),
            @ApiImplicitParam(name = "status", value = "状态(1-正常,0-失效)", paramType = "query")
    })
    public Result<Page<OutsourcingPersonVO>> list(
            @RequestParam(required = false) String name,
            @RequestParam(required = false) String idCard,
            @RequestParam(required = false) String companyName,
            @RequestParam(required = false) String startDate,
            @RequestParam(required = false) String endDate,
            @RequestParam(required = false) Integer status,
            @RequestParam(defaultValue = "1") Integer pageNum,
            @RequestParam(defaultValue = "10") Integer pageSize) {
        return Result.success(outsourcingPersonService.queryPersonList(name, idCard, companyName,
                startDate, endDate, status, pageNum, pageSize));
    }

    /**
     * 新增外协人员
     * @param dto
     * @return
     */
    @PostMapping("/add")
    @ApiOperation("新增外协人员")
    public Result<Long> addOutsourcingPerson(@RequestBody OutsourcingPersonDTO dto) {
        return Result.success(outsourcingPersonService.addOutsourcingPerson(dto));
    }

    /**
     * 删除外协人员
     * @param id
     * @return
     */
    @DeleteMapping("/{id}")
    @ApiOperation("删除外协人员")
    public Result<Boolean> deleteOutsourcingPerson(@PathVariable Long id) {
        return Result.success(outsourcingPersonService.removeById(id));
    }

    /**
     * 修改外协人员
     * @param id
     * @param dto
     * @return
     */
    @PutMapping("/{id}")
    @ApiOperation("修改外协人员")
    public Result<Boolean> updateOutsourcingPerson(@PathVariable Long id, @RequestBody OutsourcingPersonDTO dto) {
        return Result.success(outsourcingPersonService.updateOutPerson(id, dto));
    }


}
